package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Description:
 * Date: 2025-10-18
 * Time: 18:58
 */
public class DeleteBook implements IOperation{
    public void work(BookList bookList) {
        System.out.println("删除图书！！！");

        System.out.println("请输入你要删除的图书：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        
        int currentSize = bookList.getCurrentSize();
        int i = 0;
        for (; i < currentSize - 1; i++) {
            Book book = bookList.getBooks(i);
            if(book.getName().equals(name)){
                int j = i;
                for (; j < currentSize - 1; j++) {
                    Book book1 = bookList.getBooks(j + 1);
                    bookList.setBooks(book1,j);
                }
                bookList.setBooks(null,j);
                System.out.println("删除成功！！！");
                bookList.setCurrentSize(currentSize-1);
                return;

            }
        }
        if(bookList.getBooks(i).getName().equals(name)){
            bookList.setBooks(null,i);
            System.out.println("删除成功！！！");
            bookList.setCurrentSize(currentSize-1);

            return;
        }
        System.out.println("没有你所要删除的图书！！！");


    }
}
